/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.csource.manage.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.approval.vo.LineTerritoryInfoVo;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.csource.manage.dto.CaseSourceDetailDto;
import com.icinfo.cloud.provider.punish.csource.manage.dto.CaseSourceDetailVo;
import com.icinfo.cloud.provider.punish.csource.manage.dto.CaseSourceRegisterMainInfoDto;
import com.icinfo.cloud.provider.punish.csource.manage.dto.LineInfoDto;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourcePartyInfo;
import com.icinfo.cloud.provider.punish.csource.manage.request.CaseSourceRegisterMainInfoRequest;
import com.icinfo.cloud.provider.punish.csource.manage.service.ICaseSourceRegisterMainInfoService;
import com.icinfo.cloud.provider.punish.csource.manage.vo.CaseSourcePageNewVo;
import com.icinfo.cloud.provider.punish.csource.manage.vo.CaseSourceStatisticalVo;
import com.icinfo.cloud.provider.punish.evideinv.dto.CaseSourceEventSaveDto;
import com.icinfo.cloud.provider.punish.evideinv.service.EvidenceInventoryService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.ColorSumVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述: 案源登记主表 case_source_register_main_info 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年08月12日
 */
@RestController
@RequestMapping("/punish/csource/manage")
public class CaseSourceRegisterMainInfoController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseSourceRegisterMainInfoController.class);

    @Autowired
    private ICaseSourceRegisterMainInfoService caseSourceRegisterMainInfoService;
    @Autowired
    private ISysDepartParamService sysDepartParamService;
    @Autowired
    private EvidenceInventoryService evidenceInventoryService;


    /**
     * 【V1.4.0】描述：案源列表
     * @author zhangqiang
     * @param request
     * @return
     */
    @PostMapping("/caseSourceList")
    public Result<PageResponse<CaseSourcePageNewVo>> caseSourceList(@RequestBody @Validated CaseSourceRegisterMainInfoRequest request){
        PageResponse<CaseSourcePageNewVo> result = caseSourceRegisterMainInfoService.caseSourceList(request);
        return Result.success("请求成功", result);
    }

    /**
     * 【V1.4.0】描述：案源统计
     * @author zhangqiang
     * @param request
     * @return
     */
    @PostMapping("/caseSourceStatistical")
    public Result<CaseSourceStatisticalVo> caseSourceStatistical(@RequestBody @Validated CaseSourceRegisterMainInfoRequest request){
        return Result.success("请求成功",caseSourceRegisterMainInfoService.caseSourceStatistical(request));
    }

    /**
     * 描述: 案源时效颜色统计
     * @author zhanghongqiang
     * @Date 2022/10/26
     * @param request
     * @return com.icinfo.framework.common.web.Result
     */
    @PostMapping("/caseSourceColourStatistic")
    public Result<ColorSumVo> caseSourceColourStatistic(@RequestBody @Validated CaseSourceRegisterMainInfoRequest request) {
        ColorSumVo colorSumVo = caseSourceRegisterMainInfoService.getCaseSourceColourStatistic(request);
        return Result.success(colorSumVo);
    }


    /**
     * 【V1.4.0】描述：案源登记
     * @author liyafeng
     * @date 2022/8/12
      * @param saveDto
     * @return {@link Result< String>}
     */
    @PostMapping(value = "/saveCaseSourceRegisterMainInfo")
    public Result<String> saveCaseSourceRegisterMainInfo(@RequestBody @Validated CaseSourceRegisterMainInfoDto saveDto) {
        int num=caseSourceRegisterMainInfoService.saveCaseSourceRegisterMainInfo(saveDto);
        if(num>0){
            return Result.success("案源登记成功！");
        }
        return Result.error("案源登记失败！");
    }
    /**
     * 案源修改
     * @author liyafeng
     * @date 2022/12/29
      * @param saveDto
     * @return {@link Result< String>}
     */
    @PostMapping(value = "/editCaseSourceRegisterMainInfo")
    public Result<String> editCaseSourceRegisterMainInfo(@RequestBody @Validated CaseSourceRegisterMainInfoDto saveDto) {
        int num=caseSourceRegisterMainInfoService.editCaseSourceRegisterMainInfo(saveDto);
        if(num>0){
            return Result.success("案源修改成功！");
        }
        return Result.error("案源修改失败！");
    }

    /**
     * 【V1.4.0】描述：编辑案源登记当事人
     * @author liyafeng
     * @date 2022/8/12
     * @param saveDto
     * @return {@link Result< String>}
     */
    @PostMapping(value = "/editCaseSourcePartyInfo")
    public Result<String> editCaseSourcePartyInfo(@RequestBody @Validated CaseSourcePartyInfo saveDto) {
        List<CaseSourcePartyInfo> caseSourcePartyInfos = new ArrayList<>();
        caseSourcePartyInfos.add(saveDto);
        caseSourceRegisterMainInfoService.saveCaseSourcePartyInfo(saveDto.getCaseSourceId(),caseSourcePartyInfos);
        return Result.success("当事人编辑成功！");
    }

    /**
     * 【V1.4.0】案源详情
     * @author liyafeng
     * @date 2022/8/12
     * @param caseSourceDetailDto
     * @return {@link Result< String>}
     */
    @PostMapping(value = "/getCaseSourceDetail")
    public Result<CaseSourceDetailVo> getCaseSourceDetail(@RequestBody @Validated CaseSourceDetailDto caseSourceDetailDto) {
        CaseSourceDetailVo vo=caseSourceRegisterMainInfoService.getCaseSourceDetail(caseSourceDetailDto);
        return Result.success(vo);
    }
    /**
     * 根据机构编码获取部门条线信息
     * @author liyafeng
     * @date 2022/8/17
      * @param lineInfoDto
     * @return {@link Result< List< LineTerritoryInfoVo>>}
     */
    @PostMapping(value = "/getLineInfoListByOrgCode")
    public Result<List<LineTerritoryInfoVo>> getCaseSourceDetail(@RequestBody @Validated LineInfoDto lineInfoDto) {
        String orgCode=lineInfoDto.getOrgCode();
        List<LineTerritoryInfoVo> voList=sysDepartParamService.getLineInfoListByOrgCode(orgCode);
        return Result.success(voList);
    }

    /**
     * 【V1.4.1】描述： 根据id获取证据预览地址
     *
     * @author: zhengqiang
     * @date: 2022/9/5
     * @param: documentId
     * @return {@link Result< String>}
     **/
    @GetMapping(value = "/getEvidenceLinkByDocumentId")
    public Result<String> getEvidenceLinkByDocumentId(@RequestParam("documentId") String documentId) {
        return caseSourceRegisterMainInfoService.getEvidenceLinkByDocumentId(documentId);
    }

    /**
     * 重新同步案源
     * @author liyafeng
     * @date 2023/8/23
      * @param caseSourceDetailDto
     * @return {@link Result< String>}
     */
    @PostMapping(value = "/reSaveCaseSourceEvent")
    public Result<String > getCaseSourceDetail(@RequestBody @Validated CaseSourceEventSaveDto caseSourceDetailDto) {
        Boolean flag=evidenceInventoryService.reSaveCaseSourceEvent(caseSourceDetailDto);
        if(flag){
            return Result.success("重新同步成功");
        }else{
            return Result.error("重新同步失败");
        }
    }
}
